package com.ruoyi.web.controller.mes;

import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.kt.mes.domain.ProcessRoute;
import com.kt.mes.service.IProcessRouteService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 工艺路线Controller
 *
 * @author lzc
 * @date 2021-01-18
 */
@RestController
@RequestMapping("/mes/process_route")
public class ProcessRouteController extends BaseController
{
    @Autowired
    private IProcessRouteService processRouteService;

    /**
     * 查询工艺路线列表
     */
    @PreAuthorize("@ss.hasPermi('mes:process_route:list')")
    @GetMapping("/list")
    public TableDataInfo list(ProcessRoute processRoute)
    {
        startPage();
        List<ProcessRoute> list = processRouteService.selectProcessRouteList(processRoute);
        return getDataTable(list);
    }

    /**
     * 导出工艺路线列表
     */
    @PreAuthorize("@ss.hasPermi('mes:process_route:export')")
    @Log(title = "工艺路线", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(ProcessRoute processRoute)
    {
        List<ProcessRoute> list = processRouteService.selectProcessRouteList(processRoute);
        ExcelUtil<ProcessRoute> util = new ExcelUtil<ProcessRoute>(ProcessRoute.class);
        return util.exportExcel(list, "process_route");
    }

    /**
     * 获取工艺路线详细信息
     */
    @PreAuthorize("@ss.hasPermi('mes:process_route:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(processRouteService.selectProcessRouteById(id));
    }

    /**
     * 新增工艺路线
     */
    @PreAuthorize("@ss.hasPermi('mes:process_route:add')")
    @Log(title = "工艺路线", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ProcessRoute processRoute)
    {

        ProcessRoute query=new ProcessRoute();
        query.setPrId(processRoute.getPrId());

                if(processRouteService.selectProcessRouteList(query).isEmpty()==false){
                        return AjaxResult.error("编号已存在");
                }

        return toAjax(processRouteService.insertProcessRoute(processRoute));
    }

    /**
     * 修改工艺路线
     */
    @PreAuthorize("@ss.hasPermi('mes:process_route:edit')")
    @Log(title = "工艺路线", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ProcessRoute processRoute)
    {
        return toAjax(processRouteService.updateProcessRoute(processRoute));
    }

    /**
     * 删除工艺路线
     */
    @PreAuthorize("@ss.hasPermi('mes:process_route:remove')")
    @Log(title = "工艺路线", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {

        return toAjax(processRouteService.deleteProcessRouteByIds(ids));

    }
}
